<?php
class MMacaddress extends MY_Model {

	const STATE_DISABLED = 1;
	const STATE_ENABLED = 2;
	
	
	protected $table = 'macaddress';
	private $filter = array();

    function __construct() {
        parent::__construct();
    }
    
    public static function getState($state=NULL){
        $define = array(self::STATE_DISABLED=>'可用',self::STATE_ENABLED=>'无效');
    	if($state === NULL){
    		return $define;
    	}else{
    		return key_exists($state, $define)?$define[$state]:'';
    	}
    }
    
    
	public function getList($limit, $sort=false){
		$this->db->select( '*');
		$this->db->distinct();
		$this->db->from($this->table);
		$this->db->limit($limit['limit'],$limit['offset']);
		$this->formfilter->doFilter();
		if($sort){
		    $this->db->order_by('id', 'desc');
		}else{
		    $this->db->order_by('id', 'asc');
		}
		$query = $this->db->get();
		return $query->result();
	}
	
	public function getCount(){
		$this->db->select('count(distinct id) as num');
		$this->db->from($this->table);
		$this->formfilter->doFilter();
		$tmp = $this->db->get()->result();
		return (int)$tmp[0]->num;
	}
	
	//得到全部数量
	public function getTotalCount(){
		$this->db->select('count(id) as num');
		$this->db->from($this->table);
		$tmp = $this->db->get()->result();
		return (int)$tmp[0]->num;
	}
	
	public function getAllMac(){
	    $this->db->select('mac');
	    $this->db->from($this->table);
	    $this->db->where('status',1);
	    return $this->db->get()->result();
	}
	
	public function getById($id){
		$query = $this->db->where('id',$id)->get($this->table);
		return $query->row();
	}
	
	
}
